﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Input;
using Squog_1._1.Managers;

namespace Squog_1._1.Menu
{
    class StartWindow : MainMenuWindow
    {
        private bool FlashOn;
        private int TimeSinceFlash;
        private const int TimeForFlash = 500;

        private SpriteFont StartFont;

        private Vector2 TextPosition;

        public StartWindow()
            : base()
        {
            FlashOn = true;
            TimeSinceFlash = 0;

        }

        public override void LoadContent(ContentManager Content)
        {
            StartFont = Content.Load<SpriteFont>(@"Menu\StartFont");

            TextPosition = new Vector2((WindowManager.WindowWidth / 2) - (StartFont.MeasureString("Please Press Start").X / 2), WindowManager.WindowHeight - 56);

            base.LoadContent(Content);
        }

        public override void Update(GameTime gameTime)
        {
            TimeSinceFlash += gameTime.ElapsedGameTime.Milliseconds;
            if (TimeSinceFlash >= TimeForFlash)
            {
                TimeSinceFlash -= TimeForFlash;
                FlashOn = !FlashOn;
            }

            if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start))
                InputManager.UseGamePad = true;

            if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                InputManager.UseGamePad = false;

            if (InputManager.OnRelease(Buttons.Start, 0))
                WindowManager.ChangeWindows(new MainWindow());

            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);

            if (FlashOn)
                WindowsSpriteBatch.DrawString(StartFont, "Please Press Start", TextPosition, Color.DarkRed);
        }
    }
}
